//
//  MainTabBr.swift
//  weibo_swift
//
//  Created by dulinlong on 15/6/23.
//  Copyright © 2015年 sheji_56. All rights reserved.
//

import UIKit

class MainTabBr: UITabBar {
    
    let tabBarIemCount = 5
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let w = bounds.width / CGFloat(tabBarIemCount)
        let rect = CGRectMake(0, 0, w, bounds.height)
        var index: CGFloat = 0
        for v in subviews{
            if v is UIControl && !(v is UIButton){

                v.frame = CGRectOffset(rect, index * w, 0)
                index += index == 1 ? 2 : 1
            }
        }
        
        //设置中间的添加按钮
        composedButton.frame = CGRectOffset(rect, 2 * w, 0)
        
    }
    
    lazy var composedButton: UIButton = {
        let btn = UIButton()
        self.addSubview(btn)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setBackgroundImage((UIImage(named: "tabbar_compose_button")), forState: UIControlState.Normal)
        
        btn.setImage((UIImage(named: "tabbar_compose_icon_add_highlighted")), forState: UIControlState.Highlighted)
        btn.setBackgroundImage((UIImage(named: "tabbar_compose_button_highlighted")), forState: UIControlState.Highlighted)
        return btn
    }()
}
